Skip to content

Conversation

@likhitharl
Copy link

@likhitharl likhitharl commented Jan 23, 2026

Added conversion in method postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded ,
simple strings → raw values, complex → JSON string

Summary by CodeRabbit

  • Bug Fixes
    • Improved form-data handling so non-string values (arrays/objects) are converted to JSON strings for correct transmission.
    • Request reporting now includes the constructed form data for clearer diagnostics.
    • Added automatic certificate caching for specific authentication scenarios so subsequent requests use cached credentials.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 23, 2026

Walkthrough

The postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded method in AdminTestUtil.java now parses JSON input into form fields (serializing non-strings), sends form data via RestClient.postRequestWithFormDataBody, logs sanitized form data and URL, and conditionally caches certificates when testCaseName contains "UIN_Cookie" or "Vid_Cookie".

Changes

Cohort / File(s) Summary
Form Data and Certificate Caching Enhancement
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java
Reworked URL-encoded POST method to parse JSON input into a Map<String, String> form data structure, serializing non-string values to JSON strings. Switched to RestClient.postRequestWithFormDataBody, added logging for sanitized form data and request URL, and added conditional certificate caching for test cases containing "UIN_Cookie" or "Vid_Cookie". Minor formatting tweaks and added TypeReference usage.

Sequence Diagram

sequenceDiagram
    participant Test as Test Method
    participant AdminUtil as AdminTestUtil
    participant RestClient as RestClient
    participant HTTP as HTTP Endpoint
    participant CertsUtil as CertsUtil

    Test->>AdminUtil: postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded(inputJson, testCaseName)
    AdminUtil->>AdminUtil: Parse inputJson -> Map<String,Object>\nConvert entries -> Map<String,String> (serialize non-strings)
    AdminUtil->>AdminUtil: Log sanitized formData and request URL
    AdminUtil->>RestClient: postRequestWithFormDataBody(formData)
    RestClient->>HTTP: Execute POST request
    HTTP-->>RestClient: Response
    RestClient-->>AdminUtil: Return response
    AdminUtil->>AdminUtil: If testCaseName contains "UIN_Cookie" or "Vid_Cookie"\nderive keyName
    alt Certificate caching required
        AdminUtil->>CertsUtil: addCertificateToCache(keyName, responseBody)
        CertsUtil-->>AdminUtil: Certificate cached
    end
    AdminUtil-->>Test: Return response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

A rabbit hops through JSON leaves,
It strings up objects, trims the sheaves,
Posts the form with careful art,
Tucks a cookie, guards its part,
Certificates snug within its sleeves 🐇✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change: updating the postWithBodyAndCookieForAutoGeneratedIdForUrlEncoded method, which aligns with the primary modification in the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.40.5)
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 1398-1409: The current heuristic using startsWith("{"/"[") causes
legitimate String values like "{hello}" to be double-encoded via
mapper.writeValueAsString; update the loop that builds formValue (iterating
jsonMap entries) to treat any instance of String as a raw value (formValue =
(String) value) and only call mapper.writeValueAsString for non-String types
(e.g., List, Map, arrays, POJOs), removing the startsWith checks so strings are
never serialized.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 1414-1418: The code logs and reports full form data (see
AdminTestUtil using logger.info("Form data: " + formData.toString()) and
GlobalMethods.reportRequest(..., formData.toString(), ...)) which can leak
sensitive values; change this to either mask sensitive fields (e.g., password,
otp, token) before logging/reporting or gate the logging behind a debug flag so
only non-production debug builds emit the full payload; update the logging lines
and the argument passed to GlobalMethods.reportRequest and keep the actual call
to RestClient.postRequestWithFormDataBody(url, formData) unchanged.
🧹 Nitpick comments (1)
apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java (1)

1426-1433: Guard certificate caching on successful responses.
Avoid caching error payloads by checking status/body before storing.

♻️ Suggested guard
-			if (testCaseName.contains("UIN_Cookie") || testCaseName.contains("Vid_Cookie")) {
+			if ((testCaseName.contains("UIN_Cookie") || testCaseName.contains("Vid_Cookie"))
+					&& response != null
+					&& response.getStatusCode() >= 200 && response.getStatusCode() < 300
+					&& response.getBody() != null
+					&& !response.getBody().asString().isBlank()) {
 				String keyName = null;
 				if (testCaseName.contains("UIN_Cookie"))
 					keyName = ESIGNETUINCOOKIESRESPONSE;
 				else
 					keyName = ESIGNETVIDCOOKIESRESPONSE;
-				CertsUtil.addCertificateToCache(keyName, response.getBody().asString());
+				String certPayload = response.getBody().asString();
+				CertsUtil.addCertificateToCache(keyName, certPayload);
 			}

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In
`@apitest-commons/src/main/java/io/mosip/testrig/apirig/utils/AdminTestUtil.java`:
- Around line 1398-1412: In AdminTestUtil where jsonMap is converted to formData
(the loop that reads jsonMap entries and calls mapper.writeValueAsString), add a
null check for entry.getValue() before serializing: if value is null either skip
calling mapper.writeValueAsString and omit the key from formData or map it to an
empty string (e.g., formValue = "") instead of allowing
mapper.writeValueAsString(null) which yields the literal "null"; ensure the code
updates formData.put(entry.getKey(), formValue) accordingly and references the
same jsonMap/mapper/formData variables to locate the change.

@mohanachandran-s mohanachandran-s merged commit 9d92145 into mosip:develop Jan 27, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants